from selenium import webdriver
import config.config_test1
from tools.myLogger import logger

def myLogin():
    try:
        logger.info("初始化浏览器".center(50, "*"))
        driver = webdriver.Chrome()
        logger.info("设置浏览器最大化")
        driver.maximize_window()
        driver.get(config.config_test1.login_url)
        cookies = config.config_test1.cookies.split("; ")
        logger.info("添加cookies信息，绕过登录")
        for i in cookies:
            cookie = i.split('=')
            driver.add_cookie({'name': cookie[0], "value": cookie[1]})
        driver.get(config.config_test1.index_url)
        return driver
    except Exception as e:
        logger.error(e)
        logger.error("浏览器初始化失败，请检查环境信息")
        raise